/*
 * @Description: 自定义指令，clickbody,点击当前元素之外的地方触发函数，适用于下拉框等点击外部关闭
 *  
 * @Date: 2021-03-02 10:42:00
 */
const clickbody = {
  bind(el, binding) {
    function documentHandler(e) {
      if (el.contains(e.target)) {
        return false
      }
      if (binding.expression) {
        binding.value(e)
      }
    }
    el.__vueClickOutside__ = documentHandler
    document.addEventListener('click', documentHandler)
  },
  unbind(el) {
    document.removeEventListener('click', el.__vueClickOutside__)
    delete el.__vueClickOutside__
  },
}
export default clickbody
